package com.lej.player

import android.app.Activity
import android.os.Bundle
import android.view.View
import com.lej.player.manager.CustomManager
import com.shuyu.gsyvideoplayer.GSYVideoManager
import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack

class TestActivity : Activity() {
    private lateinit var playerView1: PlayerView
    private lateinit var playerView2: PlayerView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        setStatusBarTransparent()
        setContentView(R.layout.activity_test)
        Player.init()
        init()
    }

    private fun init() {
        playerView1 = findViewById(R.id.pv_1)
        playerView2 = findViewById(R.id.pv_2)
        playerView1.backButton.visibility = View.GONE
        playerView2.backButton.visibility = View.GONE

        GSYVideoManager.instance().isNeedMute = true
        val source = "http://vfx.mtime.cn/Video/2019/02/04/mp4/190204084208765161.mp4"
        setConfig(playerView1)
        playerView1.playTag = "v1"
        playerView1.playPosition = 1

        playerView1.setUpLazy(source, false, null, null, "")

        val source2 = "http://vfx.mtime.cn/Video/2019/03/18/mp4/190318231014076505.mp4"
        setConfig(playerView2)
        playerView2.playTag = "v2"
        playerView2.playPosition = 2
        playerView2.setUpLazy(source2, false, null, null, "")
//        playerView2.setPlayPosition
    }

    private fun setConfig(playerView: PlayerView) {
        playerView.titleTextView.visibility = View.GONE
        playerView.isStartAfterPrepared = true
        playerView.setIsTouchWiget(false)
        playerView.isReleaseWhenLossAudio = false
        playerView.isNeedShowWifiTip = false
        playerView.isAutoFullWithSize = true
        playerView.playTag = "v2"
        playerView.playPosition = 2
        playerView.isLooping = true

        playerView.setVideoAllCallBack(object : GSYSampleCallBack() {


            override fun onQuitFullscreen(url: String?, vararg objects: Any) {
                super.onQuitFullscreen(url, *objects)
//                fullKey = "null"
            }

            override fun onEnterFullscreen(url: String?, vararg objects: Any) {
                super.onEnterFullscreen(url, *objects)
//                holder.gsyVideoPlayer.getCurrentPlayer().getTitleTextView()
//                    .setText(objects[0] as String)
//                fullKey = holder.gsyVideoPlayer.getKey()
            }

            override fun onAutoComplete(url: String?, vararg objects: Any) {
                super.onAutoComplete(url, *objects)
            }
        })
    }

    override fun onPause() {
        super.onPause()
        playerView1.onVideoPause()
        playerView2.onVideoPause()
    }

    override fun onResume() {
        super.onResume()
        playerView1.onVideoResume()
        playerView2.onVideoResume()
    }

    override fun onDestroy() {
        super.onDestroy()
        CustomManager.clearAllVideo()
    }


    /**
     * 把状态栏设成透明
     */
//    @SuppressLint("ObsoleteSdkInt")
//    private fun setStatusBarTransparent() {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//            val decorView = window.decorView
//            decorView.setOnApplyWindowInsetsListener { v, insets ->
//                val defaultInsets = v.onApplyWindowInsets(insets)
//                defaultInsets.replaceSystemWindowInsets(
//                    defaultInsets.systemWindowInsetLeft,
//                    0,
//                    defaultInsets.systemWindowInsetRight,
//                    defaultInsets.systemWindowInsetBottom
//                )
//            }
//            ViewCompat.requestApplyInsets(decorView)
//            window.statusBarColor = ContextCompat.getColor(this, android.R.color.transparent)
//
//
//            window.requestFeature(Window.FEATURE_CONTENT_TRANSITIONS)
//            window.enterTransition = Explode()
//            window.exitTransition = Explode()
//        }
//    }
}
